﻿// <copyright file="admin_News_Edit.aspx.cs" company="NTalent">
// Copyright (c) 2010, NTalent, Inc. All rights reserved
// </copyright>
// <author>卢俊坤</author>
// <author>王彦博 符茂松</author>

using System;
using Net.Ntalent.Action50.Core.Controls;
using Net.Ntalent.Action50.Core.Service;
using Net.Ntalent.Action50.Core.Util;
using Net.Ntalent.Action50.DataAccess;

/// <summary>
/// 管理页面，更新某一篇news
/// </summary>
///<author>王彦博</author> 
/// <copyright>
/// Copyright (c) 2010, NTalent, Co. Ltd. All rights reserved.
/// </copyright>
/// <version>1.0.0</version>
public partial class admin_News_Edit : PageBase
{
    public admin_News_Edit()
    {
        //设置权限，使未登录用户不能访问该页
        authentication = Constants.AUTHENTICATION_ADMIN;
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        //如果不是回发，则从数据库提取该news的数据并加载到页面中
        if (!IsPostBack)
        {
            long newsId = Convert.ToInt64(Request.QueryString["newsId"]);
            T_NEWS_AND_LOGS news = new ReadOnlyService().RetrieveNewsAndLogs(newsId);
            TextBox_Title.Text = news.POST_TITLE;
            FCKeditor1.Value = news.POST_CONTENT;
        }
    }

    /// <summary>
    /// Logout
    /// </summary>
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        AuthenticationService authenticationService = new AuthenticationService();
        authenticationService.LogOut();
        Response.Redirect(Request.UrlReferrer.ToString());
    }

    /// <summary>
    /// 进行更新操作
    /// </summary>
    protected void LinkButton_submit_Click(object sender, EventArgs e)
    {
        try
        {
            long NewsId = Convert.ToInt64(Request.QueryString["newsId"]);
            T_NEWS_AND_LOGS news = new ReadOnlyService().RetrieveNewsAndLogs(NewsId);

            string title = HTMLFilter.Strip(TextBox_Title.Text.Trim());
            string content = Helper.FiltScriptAndStyle(FCKeditor1.Value);

            news.POST_TITLE = title;
            news.POST_CONTENT = content;

            EditService es = new EditService();
            es.UpdateNewsAndLogs(news);
            //弹出提示，更新成功
            Message.Text = "Update Successfully!";
            popupCmd.Text =
                "<script type='text/javascript'>$('.popup').css('display', 'block');$('#alpha').css('display', 'block');</script>";
        }
        catch
        {
            //弹出提示，更新失败
            Message.Text = "Update Failed!";
            popupCmd.Text =
                "<script type='text/javascript'>$('.popup').css('display', 'block');$('#alpha').css('display', 'block');</script>";
        }
    }
    protected void LinkButton2_Click(object sender, EventArgs e)
    {
        popupCmd.Text = string.Empty;
    }
}
